<template>
  <div class="product-industry">
    <!-- 左侧布局 -->
    <div class="leftbox">
      <!-- 标题 -->
      <div class="title">
        <img class="left" :src="left" alt="" />
        <span>重庆市主要工业产品</span
        ><img class="right" :src="right" alt="" />
      </div>
      <!-- 动画图案和echarts -->
      <div class="content">
        <!-- 年份选择器-->
        <div class="year">
          <ul class="steps">
            <li
              v-for="(item, index) in year"
              :key="index"
              :class="['li', yearActive === item && 'yearActive']"
              @click="chooseYear(item)"
            >
              {{ item }}
            </li>
          </ul>
        </div>
        <!-- 动画 -->
        <div class="contentleft">
          <img class="box" :src="box" alt="" />
          <img class="light" :src="light" alt="" />
          <img class="circle" :src="circle" alt="" />
          <img class="track" :src="track" alt="" />
          <img class="decorate" :src="decorate" alt="" />
          <img class="icon" :src="icon" alt="" />
        </div>
        <!-- echarts -->
        <div class="contentright">
          <div class="echart">
            <div class="industry">
              <img class="left" :src="left" alt="" />
              <span>{{ title }}</span>
              <img class="right" :src="right" alt="" />
            </div>
            <!-- height="43vh" -->
            <chart-block
              :isTitle="false"
              chartID="chart6"
              :optionData="optionData"
              chartType="getBar"
              height="23vh"
              style="padding:0 1vh 1vh 0"
            ></chart-block>
          </div>
          <div class="descBox">
            <div class="industry">
              <img class="left" :src="left" alt="" />
              <span>{{ title }}</span>
              <img class="right" :src="right" alt="" />
            </div>
            <div class="zhanbi">
              <div>
                <span class="num">{{ currentBox.cl || "" }}</span> {{currentBox.dw}}
              </div>
              <div>
                全国占比 <span class="percent">{{ currentBox.bz || "" }}%</span>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- 底部方框 -->
      <div class="bottombox">
        <div
          class="item"
          v-for="(item, index) in list"
          :key="index"
          :class="[activeIndex === index && 'active']"
          @click="clickItem(item.name, index)"
        >
          {{ item.name }}
        </div>
      </div>
    </div>
    <!-- 右侧布局 -->
    <div class="rightbox">
      <chart-block
        chartID="chart1314"
        :title="bartitle"
        :optionData="healthData"
        chartType="getBarRadiusBlock3"
        height="90vh"
        style="margin-top:0vh;background:rgba(0,0,0,0);border:none;box-shadow: none;width:100%"
        ref="echartsChart"
      ></chart-block>
    </div>
  </div>
</template>
<script>
import {
  getTenYearsData,
  getSomeoneYearsData,
  industrialProducts
} from "@/api/pages.js";
export default {
  components: {
    ChartBlock: () => import("@/components/chart-block")
  },
  data() {
    return {
      optionData: {},
      healthData: {},
      activeIndex: 0,
      yearActive: 2019,
      left: require("../../assets/images/product-industry/title_style-right.png"),
      right: require("../../assets/images/product-industry/title_style.png"),
      light: require("../../assets/images/product-industry/小圆底图.png"),
      circle: require("../../assets/images/product-industry/小圆.png"),
      box: require("../../assets/images/product-industry/底框.png"),
      track: require("../../assets/images/product-industry/亮点轨道.png"),
      decorate: require("../../assets/images/product-industry/icon装饰圆.png"),
      list: [
        { name: "天然气" },
        { name: "发电量" },
        { name: "钢材" },
        { name: "铝材" },
        { name: "水泥" },
        { name: "汽车" },
        { name: "摩托车" },
        { name: "微型计算机设备" },
        { name: "打印机" },
        { name: "移动通信手持机" },
        { name: "维伦纤维" },
        { name: "硫酸" },
        { name: "啤酒" },
        { name: "卷烟" },
        { name: "农用化肥" }
      ],
      year: [2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020],
      barBlockOptionDate: {},
      currentBox: {
        name: "",
        bz: "",
        cl: "",
        id: ''
      }
    };
  },
  computed: {
    title() {
      return (
        this.yearActive + "年" + this.list[this.activeIndex]["name"] + "年产量"
      );
    },
    bartitle() {
      return this.yearActive + "年主要工业产品产量同比增速变化";
    },
    icon() {
      return require(`../../assets/images/product-industry/${
        this.list[this.activeIndex]["name"]
      }.png`);
    }
  },
  mounted() {
    this.getTenYearsData("GY01", this.list[this.activeIndex]["name"]);
    this.getSomeoneYearsDatas();
    this.industrialProducts();
  },
  methods: {
    chooseYear(item) {
      this.yearActive = item;
      this.getSomeoneYearsDatas();
      this.industrialProducts();
    },
    clickItem(name, index) {
      this.activeIndex = index;
      this.getSomeoneYearsDatas();
      this.getTenYearsData();
    },
    // GY01 近十年XX产量-工业
    getTenYearsData() {
      getTenYearsData("GY01", this.list[this.activeIndex]["name"])
        .then(res => {
          this.optionData = {
            title: res.data.data.title,
            categoryAxis: res.data.data.categoryAxis, //类目轴数据
            seriesData: res.data.data.seriesData,
            color: ["#03cefa", "#f1db25", "#fd664d"],
            isLine: true,
            LinearGradientColor: [
              //柱状图渐变色
              {
                topColor: "rgba(12, 252, 255, 1)",
                bottomColor: "rgba(77,228,229, 0)"
              },
              {
                topColor: "#47FF72",
                bottomColor: "#E587FE"
              }
            ]
          };
        })
        .catch(err => {});
    },
    //XX年重庆市主要工业产品
    getSomeoneYearsDatas() {
      getSomeoneYearsData(
        "GY02",
        this.list[this.activeIndex]["name"],
        this.yearActive
      )
        .then(res => {
          this.currentBox = res.data.data.list.records[0] || {};
        })
        .catch(err => {});
    },
    //2020重庆主要工业产品产量同比增速变化params-
    industrialProducts() {
      industrialProducts("GY03", this.yearActive)
        .then(res => {
          if (res.data.code === 200) {
            //            var  data = res.data.data.seriesData[0].data.map(
            //   (item, index) => {
            //     let obj = {};
            //     obj.value = item;
            //     obj.name = res.data.data.categoryAxis[index];
            //     return obj;
            //   }
            // );
            res.data.data.seriesData[0];
            res.data.data.seriesData.forEach((item, index) => {
              var data = item.data.map((item, index) => {
                let obj = {};
                obj.value = item;
                obj.name = res.data.data.categoryAxis[index];
                return obj;
              });
              this.healthData = {
                title: "xxxx",
                total: item.unit,
                shadowBarGradientColor: {
                  //渐变色
                  topColor: "rgba(17,42,75,0.5)",
                  bottomColor: "rgba(7,116,164,0)"
                },
                left: 30,
                seriesData: data,
                interval: item.data.length > 5 ? true : false,
                colorList: ["#5bcef9", "#5bcef9"], //排名标号的背景颜色[前五名,五名以后]
                labelRightColor: "#20bcf6", //右侧label颜色
                symbol:
                  "image://"
              };
            });
            //  var  categoryAxis = res.data.data.categoryAxis;
            //  var  data = res.data.data.seriesData[0].data.map(
            //     (item, index) => {
            //       let obj = {};
            //       obj.value = item;
            //       obj.name = res.data.data.categoryAxis[index];
            //       return obj;
            //     }
            //   );
            //  var  totalList = res.data.data.seriesData[0].data.map(
            //     (item, index) => {
            //       var total  =Math.max(...res.data.data.seriesData[0].data)
            //       return total;
            //     }
            //   );
            //   this.barBlockOptionDate = {
            //     categoryAxis,
            //     data,
            //     totalList,
            //   }
          }
        })
        .catch(err => {});
    }
  }
};
</script>
<style scoped lang="scss">
@function vw($px) {
  @return ($px / 1920) * 100vw;
}
@function vh($px) {
  @return ($px / 1080) * 100vh;
}
.product-industry {
  min-width: 1000px;
  width: 100%;
  height: 100%;
  padding: 0 vw(20);
  display: flex;
  justify-content: space-between;
  .leftbox {
    width: 70vw;
    position: relative;
    .title {
      margin: 0 auto;
      margin-top: 3.3vh;
      font-size: vw(20);
      font-weight: bold;
      text-align: center;
      height: 8.75vh;
      line-height: 8.75vh;
      color: #fff;
      background: url("../../assets/images/product-industry/标题背景框.png")
        no-repeat center;
      span {
        padding: 0 vw(20);
      }
      img {
        width: vw(64);
        height: vh(6);
        vertical-align: middle;
      }
    }
    .content {
      padding-bottom: vh(100);
      width: 100%;
      padding-bottom: 10vh;
      position: relative;
      // background: url("../../assets/images/product-industry/底框.png") no-repeat
      //   center bottom;
      background-size: contain;
      display: flex;
      justify-content: space-between;
      .year {
        // height: vh(480);
        position: absolute;
        z-index: 5;
        .steps {
          .li {
            list-style-type: none;
            font-size: vw(14);
            text-align: left;
            // width: 20%;
            position: relative;
            height: 4vh;
            padding: 2vh;
            cursor: pointer;
            color: rgba($color: #fff, $alpha: 0.5);
          }
          .li::after {
            content: "";
            width: 2px;
            height: 4vh;
            background-color: #004b5a;
            position: absolute;
            left: 0%;
            top: 1.4vh;
            z-index: 0;
          }
          .li::before {
            display: block;
            content: "";
            line-height: 10px;
            width: 10px;
            border-radius: 5px;
            height: 10px;
            position: absolute;
            left: -4px;
            z-index: 3;
            top: 2.6vh;
            background: #34707a;
          }
          .yearActive {
            color: #fff;
          }
          .yearActive::before {
            background: #fff;
          }
        }
      }
      .contentleft {
        // width: vw(561);
        .box {
          position: absolute;
          bottom: 0;
          width: 70vw;
          height: vh(280);
        }
        .circle {
          position: absolute;
          width: 10vw;
          height: 4vh;
          bottom: 11.5vh;
          left: 18.2vw;
        }
        .light {
          width: 31vw;
          height: 35vh;
          position: absolute;
          bottom: 7vh;
          left: 8vw;
        }
        .track {
          width: 26vw;
          height: 13vh;
          position: absolute;
          bottom: 6vh;
          left: 10vw;
        }
        .decorate {
          width: 9vw;
          position: absolute;
          bottom: 28vh;
          left: 18vw;
          animation: breathe 3s infinite;
        }
        .icon {
          width: 3.5vw;
          position: absolute;
          bottom: 15.5vw;
          left: 21vw;
          animation: breathe 3s infinite;
        }
      }
      .contentright {
        .descBox,
        .echart {
          margin-top: vh(27);
          width: vw(560);
          height: vh(127);
          background: rgba(0, 75, 90, 0.24);
          border: 1px solid #00bad8;
          .industry {
            margin-top: vh(12);
            margin-bottom: vh(12);
            text-align: center;
            font-size: 1vw;
            font-family: Source Han Sans CN;
            font-weight: bold;
            color: #e7fffc;
            position: relative;
            img {
              width: vw(64);
              height: vh(6);
              vertical-align: middle;
            }
            span {
              padding: 0 vw(20);
            }
          }
          .zhanbi {
            display: flex;
            justify-content: space-around;
            font-size: vw(14);
            color: #fff;
            .percent {
              font-size: vw(32);
              color: #fdd230;
            }
            .num {
              font-size: vw(32);
              color: #0cfcff;
            }
          }
        }
        .echart {
          height: vh(295);
          width: vw(560);
          background: rgba(0, 75, 90, 0.24);
          border: 1px solid #00bad8;
        }
      }
    }
    .bottombox {
      margin-top: 2vh;
      float: left;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      .item {
        margin-top: 1.5vh;
        width: 13vw;
        height: 7vh;
        line-height: 7vh;
        font-size: vw(18);
        font-family: Source Han Sans CN;
        font-weight: 500;
        color: #e7fffc;
        background: url("../../assets/images/product-industry/未选中框.png")
          no-repeat;
        background-size: 100% 100%;
        text-align: center;
        cursor: pointer;
      }
      .active {
        background: url("../../assets/images/product-industry/选中框.png")
          no-repeat;
        background-size: 100% 100%;
      }
    }
  }
  .rightbox {
    margin-top: 6.3vh;
    width: 26vw;
  }
}

@keyframes breathe {
  0% {
    transform: translateY(-1vh);
  }
  50% {
    transform: translateY(0);
  }
  100% {
    transform: translateY(-1vh);
  }
}
</style>
